package cn.xgj.sfzy.controller;

import cn.xgj.sfzy.entity.CourseEvaluation;
import cn.xgj.sfzy.service.CourseEvaluationService;
import cn.xgj.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CourseEvaluationController
 * @Description TODO
 * @Author xgj
 * @Date 2024年10月24日 上午10:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/courseEvaluation")
public class CourseEvaluationController {
    @Autowired
    private CourseEvaluationService courseEvaluationService;

    @RequestMapping("/findAll")
    public Result findAll(CourseEvaluation courseEvaluation){
        List<CourseEvaluation> list = courseEvaluationService.findAll(courseEvaluation);
        return Result.success(list);
    }
    @RequestMapping("/findByPage")
    public Result findByPage(
            @RequestParam(required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(required = false,defaultValue = "2") Integer pageSize,
            CourseEvaluation courseEvaluation){
        PageInfo<CourseEvaluation> byPage = courseEvaluationService.findByPage(pageNum, pageSize, courseEvaluation);
        return Result.success(byPage);
    }

    @PostMapping
    public Result add(@RequestBody CourseEvaluation courseEvaluation){
        int num = courseEvaluationService.add(courseEvaluation);
        if(num!=0){
            return Result.success("添加成功");
        }else{
            return Result.error("添加失败");
        }
    }

    @PutMapping
    public Result update(@RequestBody CourseEvaluation courseEvaluation){
        int num = courseEvaluationService.edit(courseEvaluation);
        if(num!=0){
            return Result.success("修改成功");
        }else{
            return Result.error("修改失败");
        }
    }

    @DeleteMapping("/{courseEvaluationId}")
    public Result delete(@PathVariable(value = "courseEvaluationId") Integer courseEvaluationId){
        int num = courseEvaluationService.remove(courseEvaluationId);
        if(num!=0){
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }
    @GetMapping("/findByCourseId")
    public Result findByCourseId(@Param("courseId") Integer courseId){
        List<CourseEvaluation> list = courseEvaluationService.findByCourseId(courseId);
        if (list!=null){
            return Result.success(list);
        }else{
            return Result.error("没有数据");
        }
    }
    @GetMapping("/findByConsultId")
    public Result findByConsultId(
            @RequestParam(required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(required = false,defaultValue = "3") Integer pageSize,
             Integer consultId){
        PageInfo<CourseEvaluation> list = courseEvaluationService.findByConsultId(pageNum, pageSize, consultId);
        if (list!=null){
            return Result.success(list);
        }else{
            return Result.error("没有数据");
        }
    }
    
}
